#include <bits/stdc++.h>
// 2025/01/21
// tag: 
// Author: Zhang Muen
using namespace std;

class UF
{
public:
    vector<int> parents;
    int cnt;

    UF(int n)
    {
        cnt = n;
        for (int i = 0; i < n; i++)
            parents.push_back(i);
    };

    int find(int i)
    {
        if (parents[i] != i)
            return parents[i] = find(parents[i]);
        return parents[i];
    }

    void un(int i, int j)
    {
        int ri = find(i), rj = find(j);
        if (ri == rj)
            return;
        parents[ri] = rj;
        cnt--;
    }

    int count()
    {
        return cnt;
    }

    bool connected(int p, int q)
    {
        return find(p) == find(q);
    }
};

int n, m, k;
unordered_map<string, int> name;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    UF uf(n);
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        name[s] = i;
    }
    for (int i = 0; i < m; i++)
    {
        string s1, s2;
        cin >> s1 >> s2;
        uf.un(name[s1], name[s2]);
    }
    cin >> k;
    for (int i = 0; i < k; i++)
    {
        string s1, s2;
        cin >> s1 >> s2;
        if (uf.connected(name[s1], name[s2]))
            cout << "Yes." << endl;
        else
            cout << "No." << endl;
    }
    return 0;
}